using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class CaracteristicsChoices : MonoBehaviour {

    Caracteristics m_currentCaracs;

    [SerializeField]
    Image[] m_attackImages;

    [SerializeField]
    Image[] m_resistanceImages;

    [SerializeField]
    Image[] m_lifeImages;

    [SerializeField]
    Text m_sideEffectText;

    bool m_configChosen;
    bool m_powerChosen;
    Dave m_dave;

    void disableAllImages()
    {
        for(int i=0; i<m_attackImages.Length; i++)
        {
            m_attackImages[i].enabled = false;
        }

        for (int i = 0; i < m_resistanceImages.Length; i++)
        {
            m_resistanceImages[i].enabled = false;
        }

        for (int i = 0; i < m_lifeImages.Length; i++)
        {
            m_lifeImages[i].enabled = false;
        }
    }

    public void OnOpenCaracMenus()
    {
        m_currentCaracs = new Caracteristics();
        disableAllImages();
        m_sideEffectText.text = "";
        m_powerChosen = m_configChosen = false;
    }


    public void ChoosePower(int index)
    {
        m_powerChosen = true;
        m_currentCaracs.Power = (Power)index;

        switch(m_currentCaracs.Power)
        {
            case Power.Heal:
                m_sideEffectText.text = "You will become really slow after using your power";
                break;
            case Power.MagicRay:
                m_sideEffectText.text = "Random pictures of boat will pass in front of your screen";
                break;
            case Power.Shockwave:
                m_sideEffectText.text = "You will DAB for 10 seconds after using your power";
                break;
        }
    }

    public void chooseConfig(int index)
    {
        // 0 attack
        // 1 Resistance
        // 2 Life

        m_configChosen = true;
        disableAllImages();

        switch(index)
        {
            case 0:
                m_currentCaracs.Attack = 30;
                m_currentCaracs.Resistance = 4;
                m_currentCaracs.LifeAmount = 50;

                for (int i = 0; i < m_attackImages.Length; i++)
                    m_attackImages[i].enabled = true;

                for (int i = 0; i < m_resistanceImages.Length / 2; i++)
                    m_resistanceImages[i].enabled = true;

                for (int i = 0; i < m_lifeImages.Length /4; i++)
                    m_lifeImages[i].enabled = true;


                break;
            case 1:
                m_currentCaracs.Attack = 7;
                m_currentCaracs.Resistance = 9;
                m_currentCaracs.LifeAmount = 75;

                for (int i = 0; i < m_attackImages.Length / 4; i++)
                    m_attackImages[i].enabled = true;

                for (int i = 0; i < m_resistanceImages.Length; i++)
                    m_resistanceImages[i].enabled = true;

                for (int i = 0; i < m_lifeImages.Length / 2; i++)
                    m_lifeImages[i].enabled = true;

                break;
            case 2:
                m_currentCaracs.Attack = 15;
                m_currentCaracs.Resistance = 0;
                m_currentCaracs.LifeAmount = 100;

                for (int i = 0; i < m_attackImages.Length /2; i++)
                    m_attackImages[i].enabled = true;

                for (int i = 0; i < m_resistanceImages.Length / 4; i++)
                    m_resistanceImages[i].enabled = true;

                for (int i = 0; i < m_lifeImages.Length; i++)
                    m_lifeImages[i].enabled = true;

                break;
            default:
                break;
        }
    }



    // Use this for initialization
    void Start ()
    {
        m_dave = FindObjectOfType<Dave>();
        m_dave.Activated = false;
	}
	
	// Update is called once per frame
	void Update () {
		
	}

    public void validCaracs()
    {
        if (!m_configChosen || !m_powerChosen)
            return; // TODO POpup

        m_dave.initDave(m_currentCaracs);
        GameManager.m_caracteristics = m_currentCaracs;
        m_dave.Activated = true;
        gameObject.SetActive(false);
        GameManager.m_gameStarted = true;
        FindObjectOfType<GameManager>().startFight();

    }

}

public enum Power
{
    Shockwave,
    MagicRay,
    Heal
}

public class Caracteristics : MonoBehaviour
{
    int m_attack;
    int m_resistance;
    int m_life_amount;
    Power m_power;

    public int Attack {  get { return m_attack; } set { m_attack = value; } }
    public int Resistance { get { return m_resistance; } set { m_resistance = value; } }
    public int LifeAmount { get { return m_life_amount; } set { m_life_amount = value; } }
    public Power Power { get { return m_power; } set { m_power = value; } }

}
